<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>webflux</title>
</head>
<body>
<h1>哈哈</h1>
<div id="app" style="width: 500px;height: 300px;background-color: gainsboro">

</div>

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script>

    <!--创建实例-->
    const instant = axios.create({
        baseURL: 'http://localhost:8080/',
        timeout: 10000,
        responseType: 'stream',
        onDownloadProgress: function (progressEvent) {
            // 对原生进度事件的处理
            // console.log("progressEvent->", progressEvent.event.currentTarget.responseText)
            document.getElementById("app").innerHTML=
                progressEvent.event.currentTarget.responseText+"<br/>"
        //responseText 就是sse的完整数据
        },

    });

    // 为给定 ID 的 user 创建请求
    instant.get('webflux/sse')
        .then(function (response) {
            console.log(response);
        })
        .catch(function (error) {
            console.log(error);
        });

    // 上面的请求也可以这样做
    // instant.get('/user', {
    //     params: {
    //         ID: 12345
    //     }
    // })
    //     .then(function (response) {
    //         console.log(response);
    //     })
    //     .catch(function (error) {
    //         console.log(error);
    //     });
</script>

</body>
</html>